package com.demo.common.util.file;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @function:  自定义资源映射，设置虚拟路径，访问绝对路径下资源
 * @Author: amayer
 * @Date: 2022/10/12
 */

@Configuration
public class FileConfigure implements WebMvcConfigurer {
    //文件保存路径
    @Value("${file.saveFilePath}")
    private String saveFilePath;

    //访问虚拟路径
    @Value("${file.staticAccessPath}")
    private String staticAccessPath;

    //虚拟路径配置
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + saveFilePath);
    }
}
